package com.ruoyi.kesheSys.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.kesheSys.domain.vo.PopulationInfoVo;
import com.ruoyi.kesheSys.to.BusinessTo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kesheSys.domain.PopulationInfo;
import com.ruoyi.kesheSys.service.IPopulationInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人口基本信息Controller
 * 
 * @author keshe
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/kesheSys/rk")
public class PopulationInfoController extends BaseController
{
    @Autowired
    private IPopulationInfoService populationInfoService;

    /**
     * 查询人口基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:list')")
    @GetMapping("/list")
    public TableDataInfo list(PopulationInfo populationInfo)
    {
        startPage();
        List<PopulationInfoVo> list = populationInfoService.selectPopulationInfoListVo(populationInfo);
        return getDataTable(list);
    }

    /**
     * 导出人口基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:export')")
    @Log(title = "人口基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PopulationInfo populationInfo)
    {
        List<PopulationInfo> list = populationInfoService.selectPopulationInfoList(populationInfo);
        ExcelUtil<PopulationInfo> util = new ExcelUtil<PopulationInfo>(PopulationInfo.class);
        util.exportExcel(response, list, "人口基本信息数据");
    }

    /**
     * 获取人口基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(populationInfoService.selectPopulationInfoById(id));
    }

    /**
     * 新增人口基本信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:add')")
    @Log(title = "人口基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PopulationInfo populationInfo)
    {
        return toAjax(populationInfoService.insertPopulationInfo(populationInfo));
    }

    /**
     * 修改人口基本信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:edit')")
    @Log(title = "人口基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PopulationInfo populationInfo)
    {
        return toAjax(populationInfoService.updatePopulationInfo(populationInfo));
    }

    /**
     * 删除人口基本信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:rk:remove')")
    @Log(title = "人口基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(populationInfoService.deletePopulationInfoByIds(ids));
    }

    /**
     * 查询所有人口的男女比例
     *
     * @return 性别比例统计数据
     */
    @GetMapping("/statistics/gender")
    public AjaxResult getGlobalGenderStatistics() {
        BusinessTo genderStats = populationInfoService.selectGlobalGenderStatistics();
        return AjaxResult.success(genderStats);
    }

    /**
     * 查询所有人口的年龄分布
     *
     * @return 年龄分布统计数据
     */
    @GetMapping("/statistics/age")
    public AjaxResult getGlobalAgeDistribution() {
        BusinessTo ageStats = populationInfoService.selectGlobalAgeDistribution();
        return AjaxResult.success(ageStats);
    }


    /**
     * 动态获取每个区域的人口统计信息
     */
    @GetMapping("/statistics/population")
    public AjaxResult getPopulationCountByRegion() {
        List<BusinessTo> populationData = populationInfoService.selectPopulationCountByRegion();
        return AjaxResult.success(populationData);
    }
}









